/**
 * Copyright 2022 meituan.com Inc. All Rights Reserved.
 */
package org.example.server.context;

import org.example.api.Dog;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author zhangxiaofan08
 * @version 1.0 2022/3/1
 */
public class DogContext {
    private static final ConcurrentHashMap<String, Dog> MAP = new ConcurrentHashMap<>();

    public static void set(String key, Dog value) {
        MAP.put(key, value);
    }

    public static void setAll(Map<String, Dog> map) {
        MAP.putAll(map);
    }

    public static Dog get(String key) {
        Dog dog = MAP.get(key);
        if (dog == null) {
            throw new RuntimeException(key + "不存在");
        }
        return dog;
    }

    public static void remove(String key) {
        MAP.remove(key);
    }
}
